<?php
	####################################################
	# library import and object instance.              #
	####################################################
	# 커먼 인클루드
	include_once( '../common.php' );

	####################################################
	# request data($_POST AND $_GET FROM $_REQUEST)    #
	####################################################
	# REQUEST(get and post variables)
	$req = Request::clean_request($_REQUEST, 0);
	//Nlog::puts($req);
	# GET(url variables)

	# POST(form variables)
	$pmode = Request::clean_individual($_POST['mode']);


	//Nlog::puts('pmode', $pmode);
	//Nlog::puts('preturl', $preturl);

	# Validation(special case validate)
	//*/
	//Nlog::puts('req',$req); //display clean and remmap values
	//*/
	####################################################
	# implementation                                   #
	####################################################
	$sec->set_cookie_check();
	//$sec->individual_access();

	switch($pmode):
		case "signin":
			$preturl = Request::clean_individual($_POST['returl']);
			Validation::check_is_idpw($req['id']);
			Validation::check_is_idpw($req['passwd']);

			# 사인 지속
			#when type example right text>> y|naiyumie (encrypted)
			if($req['sign_duration'] == 'y'){
				Cookier::set('sign_duration_cookie', 'y'.Cookier::$separate_key.Cipher::encrypt($req['id']));
			} else {
				Cookier::del('sign_duration_cookie');
			}

			$ret = $auth->admin_check($req['id'], $req['passwd']);
			if($ret == TRUE){
				Mover::redirect(ADMIN_INDEX_FILE, TRUE);
			} else {
				Mover::redirect('admin.auth.signin?mode=false', TRUE);
			}
		break;

		case "signout":
			$ret = $dbsess->sess_delete();
			if($ret > 0){
				Mover::redirect('admin.auth.signin?mode=signout');
			}
		break;

		case "signout_ajax":
			$ret = $dbsess->sess_delete();
			if($ret > 0){
				echo(sprintf('{"result":"success"}'));
				exit();
			} else {
				echo(sprintf('{"result":"failed"}'));
				exit();
			}
		break;

		default :
		break;
	endswitch;
?>